﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Security;
using Htss.Platform.Web;

namespace DreamBox.Web.Box.user
{
    public class ajaxforfriendsBox:ControllerBox
    {
        public string Load()
        {
            string result = "";
            switch (Request.Form["t"])
            {
                case "FriendsAdd":
                    result=FriendsAdd();
                    break;
                case "FriendsDelete":
                   result= FriendsDelete();
                    break;
                case "FriendsLaunchDelete":
                    result=FriendsLaunchDelete();
                    break;
                case "FriendsLaunchAdd":
                    result=FriendsLaunchAdd();
                    break;
            }
            return result;
        }
        //
        // GET: /user/ajax/
        /// <summary>
        /// 删除好友
        /// </summary>
        /// <returns></returns>
        public string FriendsDelete()
        {
            string result = "";
           
            if (Request.Form["FriendsUser"] != null)
            {
                DAL.User.Friends friends = new DAL.User.Friends();
                Htss.Platform.Data.GHashTable hashTbl = friends.Delete(int.Parse(Session["UserID"].ToString()), int.Parse(Request.Form["FriendsUser"]));
                result = hashTbl["@returnMsg"].ToString();
            }
           
            return result;
        }
        /// <summary>
        /// 审核好友
        /// </summary>
        /// <returns></returns>
        public string FriendsAdd()
        {
            string result = "";

            if (Request.Form["LaunchID"] != null)
            {
                DAL.User.Friends friends = new DAL.User.Friends();
                Htss.Platform.Data.GHashTable hashTbl = friends.Add(int.Parse(Request.Form["LaunchID"]));
                result = hashTbl["@returnMsg"].ToString();
            }
   
            return result;
        }
        /// <summary>
        /// 删除好友申请
        /// </summary>
        /// <returns></returns>
        public string FriendsLaunchDelete()
        {
            string result = "";
           
            if (Request.Form["LaunchID"] != null)
            {
                DAL.User.FriendsLaunch friends = new DAL.User.FriendsLaunch();
                if (friends.Delete(int.Parse(Request.Form["LaunchID"])))
                {
                    result = "操作成功";
                }
            }
           
            return result;
        }
        /// <summary>
        /// 好友申请
        /// </summary>
        /// <returns></returns>
        public string FriendsLaunchAdd()
        {
            string result = "";
            
            if (Request.Form["TargetUser"] != null)
            {
                DAL.User.FriendsLaunch friends = new DAL.User.FriendsLaunch();
                Model.UserFriendsLaunch m = new Model.UserFriendsLaunch();
                m.LaunchUser = int.Parse(Session["UserID"].ToString());
                m.TargetUser = int.Parse(Request.Form["TargetUser"]);

                Htss.Platform.Data.GHashTable hashTbl = friends.Add(m);

                result = hashTbl["@returnMsg"].ToString();
            }
           
            return result;
        }
    }
}
